<template>
  <el-breadcrumb class="app-breadcrumb" separator="/">
    <el-breadcrumb-item v-for="(item) in levelList" :key="item.path">
      <a @click.prevent="handleLink(item.path)">{{ item.name }}</a>
    </el-breadcrumb-item>
  </el-breadcrumb>
</template>

<script>
import { routerTable } from './../../../utils/Router'

export default {
  data() {
    return {
      levelList: []
    }
  },
  watch: {
    $route(route) {
      this.getBreadcrumb()
    }
  },
  created() {
    this.getBreadcrumb()
  },
  methods: {
    getBreadcrumb() {
      this.levelList = []
      let matched = this.$route.matched
      console.log(matched)
      // 在routerTable中搜索符合的
      matched.forEach(element => {
        routerTable.forEach(item => {
          if (element.path == item.path) {
            this.levelList.push(item)
          }
        });
      });

    },
    // pathCompile(path) {
    //   const { params } = this.$route
    //   var toPath = pathToRegexp.compile(path)
    // },
    handleLink(item) {
      console.log(item)
      this.$router.push({ path: item })
    }
  }
}
</script>

<style scoped>
.app-breadcrumb.el-breadcrumb {
  display: inline-block;
  font-size: 14px;
  line-height: 50px;
  margin-left: 8px;
}

.no-redirect {
  color: #97a8be;
  cursor: text;
}
</style>
